package com.shadow.baiqun.delegate.send;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.shadow.core.util.date.DateUtils;
import com.shadow.ui.recycler.ObjConverter;

import java.util.ArrayList;

/**
 * @author zy
 *         on 2018/6/26
 */
public class SendGoodsConverter {

    public ArrayList<SendGoodsEntity> convert(String response) {
        ArrayList<SendGoodsEntity> list = new ArrayList<>();
        try {
            final JSONArray jsonArray = JSONObject.parseObject(response)
                    .getJSONArray("rows");
            final int size = jsonArray.size();
            for (int i = 0; i < size; i++) {
                final JSONObject object = jsonArray.getJSONObject(i);
                SendGoodsEntity sendGoodsEntity = new ObjConverter<SendGoodsEntity>().
                        convert(object.toJSONString(), new TypeReference<SendGoodsEntity>() {
                        });
                sendGoodsEntity.setAddTime(DateUtils.longToString(
                        Long.valueOf(sendGoodsEntity.getAddTime())));
                list.add(sendGoodsEntity);
            }
            return list;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }
}
